// 1. 连接数据库
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/muzi',{ useNewUrlParser: true })
    .then(()=> console.log('数据库连接成功'))
    .catch(err =>console.log(err,'数据库连接失败'))

// 2. 创建用户集合
var userSchema = mongoose.Schema({
   // 用户名
    'name': {type: String},
   // 密码
    'pwd': {type: String},
   //  手机
    'phone': {type: String},
   // 最后操作时间
    'l_time': {type: Date, default: Date.now}
});

// 3. 输出文档(model)
const User = mongoose.model('user', userSchema);
const user = new User({
    name:'admin22',
    pwd:'123456',
    phone:'13511112222'

});
// User.create({name:'admin',pwd:'111111',phone:'12311112223'})
//     .then(doc => console.log(doc))
//     .catch(err=> console.log(err))

module.exports = User;